package com.chen.blue.controller.admin.system;


import com.chen.blue.domain.delete.system.MenuRoleDelete;
import com.chen.blue.domain.delete.system.UserRoleDelete;
import com.chen.blue.domain.dto.system.MenuRoleDto;
import com.chen.blue.domain.dto.system.UserRoleDto;
import com.chen.blue.domain.dto.system.update.MenuRoleDtoEdit;
import com.chen.blue.domain.dto.system.update.UserRoleDtoEdit;
import com.chen.blue.exception.e.DtoNullException;
import com.chen.blue.result.R;
import com.chen.blue.service.system.IMenuRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author CLT
 * @since 2024-05-09
 */
@Api(tags = "角色菜单模块")
@Validated
@RestController
@RequestMapping("/role/menu")
public class MenuRoleController {

    @Resource
    private IMenuRoleService iMenuRoleService;

    //    @ApiOperation(value = "角色菜单添加", notes = "角色菜单添加")
    @PostMapping("/add")
    public R add(@RequestBody @Valid List<MenuRoleDto> menuRoleDtoList) throws DtoNullException {

        return iMenuRoleService.addRoleMenu(menuRoleDtoList) ? R.success() : R.faild();

    }

    //    @ApiOperation(value = "角色菜单删除", notes = "角色菜单删除")
    @DeleteMapping("/delete")
    public R delete(@RequestBody @Valid MenuRoleDelete menuRoleDelete) throws DtoNullException {

        return iMenuRoleService.deleteRoleMenu(menuRoleDelete) ? R.success() : R.faild();

    }

    //    @ApiOperation(value = "角色菜单修改", notes = "角色菜单修改")
    @PutMapping("/edit")
    public R updateById(@RequestBody @Valid List<MenuRoleDtoEdit> menuRoleDtoEditList) throws DtoNullException {

        return iMenuRoleService.updateRoleMenu(menuRoleDtoEditList) ? R.success() : R.faild();

    }

    @ApiOperation(value = "角色ID查询角色菜单", notes = "角色ID查询角色菜单")
    @GetMapping("/queryById/{id}")
    public R queryById(@PathVariable("id") Long roleId) throws DtoNullException {

        return R.success(iMenuRoleService.queryMenuById(roleId));

    }

}

